
package com.chessimo.printer;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;

import com.chessimo.config.ConfigControl;
import com.chessimo.config.Definitions;
import com.chessimo.main.Chess;


public class PrinterHome implements MouseListener, MouseMotionListener {    
    
    private int frameWidth;
    private int frameHeight;   
    private static JButton butInfo = new JButton();
    private static JButton butConfig = new JButton();
    private static JButton butTraining = new JButton();
    private static JButton butVerify = new JButton(); 
    private static JButton butPlay = new JButton();
    
    
    public PrinterHome(int frameWidth, int frameHeight){
    	this.frameWidth = frameWidth;
    	this.frameHeight = frameHeight;
    }
    
    
    public void print() {
        Chess.tHome.setText("Bem-vindo " + ConfigControl.user);
        printButInfo("Info");
        printButConfig("Config");
        printLogoChessimo("images/logochessimo.jpg");
        printButTraining("TREINAR");
        printButVerify("VERIFICAR");
        printButPlay("JOGAR");
    }
    
    
    public void printButInfo(String txt) {
        
        int pos1 = frameWidth - 305;
        int pos2 = 5;
        
        int butWidth = 140;
        int butHeight = 30;
        
        butInfo.setText(txt);
        butInfo.setBounds(pos1, pos2, butWidth, butHeight);
        butInfo.setFont(Definitions.fontButtons);
        Chess.pHome.add(butInfo, new Integer(3));
        
        butInfo.addMouseListener(this);
   
    }
    
    public void printButConfig(String txt) {
 
        int pos = frameWidth - 160; 
        
        butConfig.setText(txt);
        butConfig.setBounds(pos, 5, 140, 30);
        butConfig.setFont(Definitions.fontButtons);
        Chess.pHome.add(butConfig, new Integer(3));
        
        butConfig.addMouseListener(this);
        
    }

    public void printLogoChessimo(String logoImg) {
        
        int imgWidth = 270;
        int imgHeight = 91;
        
        int pos1 = (frameWidth / 2) - (imgWidth / 2);
        int pos2 = (frameHeight / 2) - (imgHeight / 2) - (frameHeight / 3);
        
        ImageIcon logo = new ImageIcon(logoImg);       
        
        JLabel labLogo = new JLabel(logo, 0);
        labLogo.setBounds(pos1, pos2, imgWidth, imgHeight);
        
        Chess.pHome.add(labLogo, new Integer(3)); 
        
        labLogo.addMouseListener(this);
        
    }    
    
    
    public void printButTraining(String txt) {
 
        int butWidth = 180;
        int butHeight = 150;
        
        int pos1 = (frameWidth / 2) - (butWidth / 2) - 200; 
        int pos2 = (frameHeight / 2) - (butHeight / 2) - (frameHeight / 10);
        
        butTraining.setText(txt);
        butTraining.setBounds(pos1, pos2, butWidth, butHeight);
        butTraining.setFont(Definitions.fontButtonsMenu);
        Chess.pHome.add(butTraining, new Integer(3));
        
        butTraining.addMouseListener(this);
        butTraining.addMouseMotionListener(this);

    }    
    
    
    public void printButVerify(String txt) {
 
        int butWidth = 180;
        int butHeight = 150;
        
        int pos1 = (frameWidth / 2) - (butWidth / 2); 
        int pos2 = (frameHeight / 2) - (butHeight / 2) - (frameHeight / 10);

        butVerify.setText(txt);
        butVerify.setBounds(pos1, pos2, butWidth, butHeight);
        butVerify.setFont(Definitions.fontButtonsMenu);
        Chess.pHome.add(butVerify, new Integer(3));
        
        butVerify.addMouseListener(this);

    }     
    
    
    public void printButPlay(String txt) {
 
        int butWidth = 180;
        int butHeight = 150;
        
        int pos1 = (frameWidth / 2) - (butWidth / 2) + 200; 
        int pos2 = (frameHeight / 2) - (butHeight / 2) - (frameHeight / 10);

        butPlay.setText(txt);
        butPlay.setBounds(pos1, pos2, butWidth, butHeight);
        butPlay.setFont(Definitions.fontButtonsMenu);
        Chess.pHome.add(butPlay, new Integer(3));
        
        butPlay.addMouseListener(this);
        

    } 

    @Override
    public void mouseClicked(MouseEvent e) {
        
        if (e.getSource() == butTraining) {
            try {
                Chess.selector(80);
            } catch (FileNotFoundException ex) {
                Logger.getLogger(PrinterHome.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(PrinterHome.class.getName()).log(Level.SEVERE, null, ex);
            }
        } 
        
        if (e.getSource() == butInfo) {
            try {
                Chess.selector(2);
            } catch (FileNotFoundException ex) {
                Logger.getLogger(PrinterHome.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(PrinterHome.class.getName()).log(Level.SEVERE, null, ex);
            }
        }   
        
        if (e.getSource() == butConfig) {
            PrinterConfiguration.setReferer("home");
            try {
                Chess.selector(4);
            } catch (FileNotFoundException ex) {
                Logger.getLogger(PrinterHome.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(PrinterHome.class.getName()).log(Level.SEVERE, null, ex);
            }
        }  
        
    }

    @Override
    public void mousePressed(MouseEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");

    }

    @Override
    public void mouseReleased(MouseEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");

    }

    @Override
    public void mouseEntered(MouseEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void mouseExited(MouseEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void mouseDragged(MouseEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void mouseMoved(MouseEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    
    
}
